package com.intellagric.service.impl.module.loganalyse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.LogAnalyzeJobConditionMapper;
import com.intellagric.pojo.LogAnalyzeJobCondition;
import com.intellagric.pojo.LogAnalyzeJobConditionExample;
import com.intellagric.service.module.loganalyse.LogAnalyseJobConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: zhy
 * @Date: 2019/5/11
 * @Description: 日志分析过滤规则管理服务
 */
@Service
public class LogAnalyseJobConditionServiceImpl implements LogAnalyseJobConditionService {

    @Autowired
    private LogAnalyzeJobConditionMapper logAnalyzeJobConditionMapper;

    /**
    * 添加日志分析过滤规则信息
    * @param logAnalyzeJobCondition
    * @return int
    */
    public ResponseMessage addLogAnalyzeJobCondition(LogAnalyzeJobCondition logAnalyzeJobCondition) {
        if (logAnalyzeJobConditionMapper.insertSelective(logAnalyzeJobCondition) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }
    
    /**
     * 删除日志分析过滤规则信息
     * @param id
     * @return int
     */
    public ResponseMessage deleteLogAnalyzeJobCondition(int id) {
        if (logAnalyzeJobConditionMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }
    
    /**
     * 修改日志分析过滤规则信息
     * @param logAnalyzeJobCondition
     * @return int
     */
    public ResponseMessage editLogAnalyzeJobCondition(LogAnalyzeJobCondition logAnalyzeJobCondition) {
        if (logAnalyzeJobConditionMapper.updateByPrimaryKeySelective(logAnalyzeJobCondition) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }
    
    /**
     * 通过id查询日志分析过滤规则
     * @param id
     * @return LogAnalyzeJobCondition
     */
    public LogAnalyzeJobCondition queryLogAnalyzeJobConditionById(int id) {
        return logAnalyzeJobConditionMapper.selectByPrimaryKey(id);
    }

    /**
     * 通过jobid查询日志分析过滤规则
     * @param jobid
     * @return LogAnalyzeJobCondition
     */
    public LayuiDataGridResult queryLogAnalyzeJobConditionByJobId(int jobid) {
        LogAnalyzeJobConditionExample logAnalyzeJobConditionExample = new LogAnalyzeJobConditionExample();
        logAnalyzeJobConditionExample.createCriteria().andJobidEqualTo(jobid);
        List<LogAnalyzeJobCondition> logAnalyzeJobConditionList = logAnalyzeJobConditionMapper.selectByExample(logAnalyzeJobConditionExample);
        return LayuiDataGridResult.success().add(logAnalyzeJobConditionList,logAnalyzeJobConditionList.size());
    }
    
    /**
     * 查询所有日志分析过滤规则信息
     * @return List<LogAnalyzeJobCondition>
     */
    public LayuiDataGridResult queryLogAnalyzeJobConditionList() {
        LogAnalyzeJobConditionExample logAnalyzeJobConditionExample = new LogAnalyzeJobConditionExample();
        logAnalyzeJobConditionExample.createCriteria().andIdIsNotNull();
        List<LogAnalyzeJobCondition> logAnalyzeJobConditionList = logAnalyzeJobConditionMapper.selectByExample(logAnalyzeJobConditionExample);
        return LayuiDataGridResult.success().add(logAnalyzeJobConditionList,logAnalyzeJobConditionList.size());
    }
    
    /**
     * 分页查询所有日志分析过滤规则记录
     * @return List<LogAnalyzeJobCondition>
     */
    public LayuiDataGridResult queryLogAnalyzeJobConditionPage(int page, int rows) {
        PageHelper.startPage(page, rows);
        LogAnalyzeJobConditionExample LogAnalyzeJobConditionExample = new LogAnalyzeJobConditionExample();
        LogAnalyzeJobConditionExample.createCriteria().andIdIsNotNull();
        List<LogAnalyzeJobCondition> logAnalyzeJobConditionList = logAnalyzeJobConditionMapper.selectByExample(LogAnalyzeJobConditionExample);
        PageInfo<LogAnalyzeJobCondition> pageInfo = new PageInfo<>(logAnalyzeJobConditionList);
        return LayuiDataGridResult.success().add(logAnalyzeJobConditionList,pageInfo.getTotal());
    }


}
